<%@ page contentType="text/html; charset=UTF-8" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>


<c:if test="${empty USER}">
    <jsp:forward page="login.html"/>
</c:if>
<jsp:include page="header.jsp"/>
    <div id="content">
        <div class="container san-serif-font">
            <div class="login-head">
                <h3>Ý kiến phản hồi</h3>
            </div>
            <div class="login-body clearfix">
                <div class="login-region">
                    <h4>Phản hồi ý kiến</h4>
                    <div>Nếu bạn có ý kiến gì hãy cho chúng tôi biết</div>
                    <form id="login-form" action="addFeedback.action" method="post">
                        <p>
                            <label class="label">Chủ đề(<font color="red">*</font>)</label>
                        </p>
                        <p>
                            <input type="text" name="titleFeedback" id="titleFeedback" class="input big-input" onblur="check(1, 50, this, document.getElementById('titleFeedback_help'))"/>
                        </p>
                        <p>
                            <span style="color:red" id="titleFeedback_help"></span>
                        </p>
                        <p>
                            <label class="label">Nội dung(<font color="red">*</font>)</label>
                        </p>
                        <p>
                            <textarea name="contentFeedback" id="contentFeedback" rows="4" cols="20" class="input big-input" style="resize:none" onblur="check(1, 300, this, document.getElementById('contentFeedback_help'))"></textarea>
                        </p>
                        <p>
                            <span style="color:red" id="contentFeedback_help"></span>
                        </p>
                        <div class="text-right">
                            <input name="btFeedback" type="button" value="Góp ý" class="big-nice-button" onclick="validateSubmit(this.form)">
                        </div>
                    </form>
                </div>
                <h3 id="notify"><font color="green">${requestScope.notification}</font></h3>
            </div>
        </div>
    </div>

<script type="text/javascript">
    function validateRegEx(regex, input, helpText, helpMessage) {
        // See if the input data validates OK
        if (!regex.test(input)) {
            // The data is invalid, so set the help message and return false
            if (helpText != null)
                helpText.innerHTML = helpMessage;
            return false;
        }
        else {
            // The data is OK, so clear the help message and return true
            if (helpText != null)
                helpText.innerHTML = "";
            return true;
        }
    }

    function validateNonEmpty(inputField, helpText) {
        // See if the input value contains any text
        return validateRegEx(/^[\S]+/,
        inputField.value, helpText,
        "Ký tự đầu tiên phải khác khoảng trắng.");
    }

    function validateLength(minLength, maxLength, inputField, helpText) {
        // See if the input value contains at least minLength but no more than maxLength characters
        return validateRegEx(new RegExp("^.{" + minLength + "," + maxLength + "}$"),
        inputField.value, helpText,
        "Chỉ được nhập từ " + minLength + " tới " + maxLength + " ký tự");
    }

    function check(minLength, maxLength, inputField, helpText) {
        if (validateNonEmpty(inputField, helpText)) {
            validateLength(minLength, maxLength, inputField, helpText)
        }
    }

    function validateSubmit(form) {
        if (validateNonEmpty(form["titleFeedback"], form["titleFeedback_help"]) &&
            validateNonEmpty(form["contentFeedback"], form["contentFeedback_help"]) &&
            validateLength(1, 50, form["titleFeedback"], form["titleFeedback_help"]) &&
            validateLength(1, 300, form["contentFeedback"], form["contentFeedback_help"])) {
            // Submit the order to the server
            form.submit();
        } else {
            alert("Nội dung không phù hợp. Xin kiểm tra lại.");
        }
    }
</script>
<script type="text/javascript" src="js/jsUtils.js"></script>
<script type="text/javascript">
    activeCurrentNav('feedbackNav');

    //Cho cai notify bien mat sau 3 giay
    setTimeout(function(){
        document.getElementById("notify").hidden = true;
    }, 3*1000);


</script>
<jsp:include page="footer.jsp"/>